package com.xmm.model;

import java.util.ArrayList;
import java.util.List;


public class Artist {
	private String mName = null;
	private List<String> mMembership = null;
	
	/**
	 * @param name
	 * @param membership
	 */
	public Artist(String name, List<String> membership) {
		mName = name;
		if(membership == null) {
			mMembership = new ArrayList<String>();
		} else {
			mMembership = membership;
		}
	}
	
	/**
	 * @param name
	 */
	public void setName(String name) {
		mName = name;
	}
	
	/**
	 * @return
	 */
	public String getName() {
		return mName;
	}
	
	/**
	 * @param name
	 */
	public void addMembership(String name) {
		if(name != null && "".equals(name) == false) {
			if(mMembership == null) {
				mMembership = new ArrayList<String>();
			}
			mMembership.add(name);
		}
	}
	
	/**
	 * @return
	 */
	public String toString() {
		StringBuilder sb = new StringBuilder();
		if(mName != null) {
			sb.append(mName);
		}
		if(mMembership.isEmpty()) {
			return sb.toString();
		}
		sb.append(':');
		for(String name : mMembership) {
			sb.append('/');
			sb.append(name);
		}
		return sb.toString();
	}
	
	public List<String> toList() {
		if(mMembership.isEmpty() && mName != null) {
			List<String> tmp = new ArrayList<String>();
			tmp.add(mName);
			return tmp;
		}
		return mMembership;
	}
	
	@SuppressWarnings("unused")
	private String search(String name) {
		if(name == null || "".equals(name)) {
			return null;
		}
		if(name.equalsIgnoreCase(mName)) {
			return mName;
		}
		for(String nm : mMembership) {
			if(name.equalsIgnoreCase(nm)) {
				return nm;
			}
		}
		return null;
	}
}
